package com.haixiaoke.flat.apartment.controller;

import com.haixiaoke.saas.apartment.domain.BusinessCircle;
import com.haixiaoke.saas.apartment.service.IBusinessCircleService;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商业区Controller
 *
 * @author xiaolong
 * @date 2023-10-25
 */
@RestController
@RequestMapping("/front/apartment/circle")
public class FlatBusinessCircleController extends BaseController {
    @Autowired
    private IBusinessCircleService businessCircleService;

    /**
     * 查询商业区列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BusinessCircle businessCircle) {
        startPage();
        List<BusinessCircle> list = businessCircleService.selectBusinessCircleList(businessCircle);
        return getDataTable(list);
    }

    /**
     * 导出商业区列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessCircle businessCircle) {
        List<BusinessCircle> list = businessCircleService.selectBusinessCircleList(businessCircle);
        ExcelUtil<BusinessCircle> util = new ExcelUtil<BusinessCircle>(BusinessCircle.class);
        util.exportExcel(response, list, "商业区数据");
    }

    /**
     * 获取商业区详细信息
     */
    @GetMapping(value = "/{businessCircleId}")
    public AjaxResult getInfo(@PathVariable("businessCircleId") Long businessCircleId) {
        return success(businessCircleService.selectBusinessCircleByBusinessCircleId(businessCircleId));
    }

    /**
     * 新增商业区
     */
    @PostMapping
    public AjaxResult add(@RequestBody BusinessCircle businessCircle) {
        return toAjax(businessCircleService.insertBusinessCircle(businessCircle));
    }

    /**
     * 修改商业区
     */
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessCircle businessCircle) {
        return toAjax(businessCircleService.updateBusinessCircle(businessCircle));
    }

    /**
     * 删除商业区
     */
    @DeleteMapping("/{businessCircleIds}")
    public AjaxResult remove(@PathVariable Long[] businessCircleIds) {
        return toAjax(businessCircleService.deleteBusinessCircleByBusinessCircleIds(businessCircleIds));
    }
}
